﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreValidationCode;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;

public partial class admin_TalkHouseSetting_TalkHouseEdit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.QueryString.Get("thl_Id") != null)
            {
                int thl_Id = int.Parse(Request.QueryString.Get("thl_Id"));
                TalkHouseListService thlService = new TalkHouseListService();
                TalkHouseList thl = thlService.findById(thl_Id);
                if (thl != null)
                {
                    this.TxtAreaName.Text = thl.TalkHouseName;
                    this.TxtTalkTheme.Text = thl.TalkHouseTheme;
                    this.TxtWelcome.Text = thl.TalkHouseWelcome;
                    this.IbtCreate.Attributes.Add("thl_Id", thl_Id.ToString());
                }
            }
        }
    }
    protected void IbtCreate_Click(object sender, EventArgs e)
    {
        string vCode = Request.Form.Get(this.TxtValidatorCode.ClientID).Trim();
        if (vCode.Equals(Code.Codes))
        {
            string thlName = Request.Form.Get(this.TxtAreaName.ClientID).Trim();
            if (!"".Equals(thlName))
            {
                string thlWelcome = Request.Form.Get(this.TxtWelcome.ClientID);
                string thlTheme = Request.Form.Get(this.TxtTalkTheme.ClientID);
                int thid = int.Parse(((Button)sender).Attributes["thl_Id"]);
                TalkHouseListService thlService = new TalkHouseListService();
                if (thlService.UpdateTalkHouseInfo(thlName, thlWelcome, thlTheme, DateTime.Now, thid) == 1)
                {
                    Response.Redirect("Index.aspx");
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('更新失败，请重试！');", true);
                }
            }
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('验证码输入错误！');", true);
        }
    }
}
